package com.allianz.webapps.controllers;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping(value="main")
public class Type099ShowPdfController {
	@RequestMapping(value="type099Showpdf")
	public void showpdf(HttpServletRequest request,HttpServletResponse response) throws IOException{
		String realPath = "g:/aaa.pdf";//获取要下载的文件的绝对路径
			String fileName = realPath.substring(realPath.lastIndexOf("\\")+1);//获取要下载的文件名
			//设置content-disposition响应头控制浏览器以下载的形式打开文件，中文文件名要使用URLEncoder.encode方法进行编码，否则会出现文件名乱码
			response.setHeader("content-disposition", "online;filename="+URLEncoder.encode(fileName, "UTF-8"));
			InputStream in = new FileInputStream(realPath);//获取文件输入流
			int len = 0;
			byte[] buffer = new byte[1024];
			OutputStream out = response.getOutputStream();
			while ((len = in.read(buffer)) > 0) {
				out.write(buffer,0,len);//将缓冲区的数据输出到客户端浏览器
			}
			in.close();
		}
}
